var o = require("../../../../../../@babel/runtime/helpers/regeneratorRuntime"), t = require("../../../../../../@babel/runtime/helpers/asyncToGenerator"), l = require("../../../../../../common/vendor.js"), e = require("../z-paging-utils.js"), i = require("../z-paging-enum.js"), r = {
    props: {
        usePageScroll: {
            type: Boolean,
            default: e.u.gc("usePageScroll", !1)
        },
        scrollable: {
            type: Boolean,
            default: e.u.gc("scrollable", !0)
        },
        showScrollbar: {
            type: Boolean,
            default: e.u.gc("showScrollbar", !0)
        },
        scrollX: {
            type: Boolean,
            default: e.u.gc("scrollX", !1)
        },
        scrollToTopBounceEnabled: {
            type: Boolean,
            default: e.u.gc("scrollToTopBounceEnabled", !1)
        },
        scrollToBottomBounceEnabled: {
            type: Boolean,
            default: e.u.gc("scrollToBottomBounceEnabled", !0)
        },
        scrollWithAnimation: {
            type: Boolean,
            default: e.u.gc("scrollWithAnimation", !1)
        },
        scrollIntoView: {
            type: String,
            default: e.u.gc("scrollIntoView", "")
        }
    },
    data: function() {
        return {
            scrollTop: 0,
            oldScrollTop: 0,
            scrollViewStyle: {},
            scrollViewContainerStyle: {},
            scrollViewInStyle: {},
            pageScrollTop: -1,
            scrollEnable: !0,
            privateScrollWithAnimation: -1,
            cacheScrollNodeHeight: -1
        };
    },
    watch: {
        oldScrollTop: function(o) {
            !this.usePageScroll && this._scrollTopChange(o, !1);
        },
        pageScrollTop: function(o) {
            this.usePageScroll && this._scrollTopChange(o, !0);
        },
        usePageScroll: {
            handler: function(o) {
                this.loaded && this.autoHeight && this._setAutoHeight(!o);
            },
            immediate: !0
        },
        finalScrollTop: function(o) {
            this.useChatRecordMode || (this.renderPropScrollTop = o < 6 ? 0 : 10);
        }
    },
    computed: {
        finalScrollWithAnimation: function() {
            if (-1 !== this.privateScrollWithAnimation) {
                var o = 1 === this.privateScrollWithAnimation;
                return this.privateScrollWithAnimation = -1, o;
            }
            return this.scrollWithAnimation;
        },
        finalScrollViewStyle: function() {
            return 1 != this.superContentZIndex && (this.scrollViewStyle["z-index"] = this.superContentZIndex, 
            this.scrollViewStyle.position = "relative"), this.scrollViewStyle;
        },
        finalScrollTop: function() {
            return this.usePageScroll ? this.pageScrollTop : this.oldScrollTop;
        },
        finalIsOldWebView: function() {
            return this.isOldWebView && !this.usePageScroll;
        }
    },
    methods: {
        scrollToTop: function(o) {
            var t = this;
            this.$nextTick(function() {
                t._scrollToTop(o, !1);
            });
        },
        scrollToBottom: function(o) {
            var t = this;
            this.$nextTick(function() {
                t._scrollToBottom(o);
            });
        },
        scrollIntoViewById: function(o, t, l) {
            this._scrollIntoView(o, t, l);
        },
        scrollIntoViewByNodeTop: function(o, t, l) {
            var e = this;
            this.scrollTop = this.oldScrollTop, this.$nextTick(function() {
                e._scrollIntoViewByNodeTop(o, t, l);
            });
        },
        scrollToY: function(o, t, l) {
            var e = this;
            this.scrollTop = this.oldScrollTop, this.$nextTick(function() {
                e._scrollToY(o, t, l);
            });
        },
        scrollIntoViewByIndex: function(o, t, l) {
            this._scrollIntoView(o, t, l);
        },
        scrollIntoViewByView: function(o, t, l) {
            this._scrollIntoView(o, t, l);
        },
        updatePageScrollTop: function(o) {
            this.pageScrollTop = o;
        },
        updatePageScrollTopHeight: function() {
            this._updatePageScrollTopOrBottomHeight("top");
        },
        updatePageScrollBottomHeight: function() {
            this._updatePageScrollTopOrBottomHeight("bottom");
        },
        updateLeftAndRightWidth: function() {
            var o = this;
            this.finalIsOldWebView && this.$nextTick(function() {
                return o._updateLeftAndRightWidth(o.scrollViewContainerStyle, "zp-page");
            });
        },
        updateScrollViewScrollTop: function(o) {
            var t = this, l = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1];
            this.privateScrollWithAnimation = l ? 1 : 0, this.scrollTop = this.oldScrollTop, 
            this.$nextTick(function() {
                t.scrollTop = o, t.oldScrollTop = t.scrollTop;
            });
        },
        _onScrollToUpper: function() {
            var o = this;
            this.$emit("scrolltoupper"), this.$emit("scrollTopChange", 0), this.$nextTick(function() {
                o.oldScrollTop = 0;
            }), this.useChatRecordMode && this.loadingStatus !== i.Enum.More.NoMore && this._onLoadingMore("click");
        },
        _onScrollToLower: function(o) {
            (!o.detail || !o.detail.direction || "bottom" === o.detail.direction) && this._onLoadingMore("toBottom");
        },
        _scrollToTop: function() {
            var o = this, t = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0];
            this.usePageScroll ? this.$nextTick(function() {
                l.index.pageScrollTo({
                    scrollTop: 0,
                    duration: t ? 100 : 0
                });
            }) : (this.privateScrollWithAnimation = t ? 1 : 0, this.scrollTop = this.oldScrollTop, 
            this.$nextTick(function() {
                o.scrollTop = 0, o.oldScrollTop = o.scrollTop;
            }));
        },
        _scrollToBottom: function() {
            var e = arguments, i = this;
            return t(o().mark(function t() {
                var r, n, c, s, a;
                return o().wrap(function(o) {
                    for (;;) switch (o.prev = o.next) {
                      case 0:
                        if (r = !(e.length > 0 && void 0 !== e[0]) || e[0], !i.usePageScroll) {
                            o.next = 5;
                            break;
                        }
                        i.$nextTick(function() {
                            l.index.pageScrollTo({
                                scrollTop: Number.MAX_VALUE,
                                duration: r ? 100 : 0
                            });
                        }), o.next = 20;
                        break;

                      case 5:
                        return o.prev = 5, i.privateScrollWithAnimation = r ? 1 : 0, o.next = 9, i._getNodeClientRect(".zp-paging-container");

                      case 9:
                        return n = o.sent, o.next = 12, i._getNodeClientRect(".zp-scroll-view");

                      case 12:
                        c = o.sent, s = n ? n[0].height : 0, a = c ? c[0].height : 0, s > a && (i.scrollTop = i.oldScrollTop, 
                        i.$nextTick(function() {
                            i.scrollTop = s - a + i.virtualPlaceholderTopHeight, i.oldScrollTop = i.scrollTop;
                        })), o.next = 20;
                        break;

                      case 18:
                        o.prev = 18, o.t0 = o.catch(5);

                      case 20:
                      case "end":
                        return o.stop();
                    }
                }, t, null, [ [ 5, 18 ] ]);
            }))();
        },
        _scrollIntoView: function(o) {
            var t = this, l = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], i = arguments.length > 3 ? arguments[3] : void 0;
            try {
                this.scrollTop = this.oldScrollTop, this.$nextTick(function() {
                    t._getNodeClientRect("#" + o.replace("#", ""), t.$parent).then(function(o) {
                        if (o) {
                            var r = o[0].top;
                            t._scrollIntoViewByNodeTop(r, l, e), i && i();
                        }
                    });
                });
            } catch (o) {}
        },
        _scrollIntoViewByNodeTop: function(o) {
            var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, l = arguments.length > 2 && void 0 !== arguments[2] && arguments[2];
            this._scrollToY(o, t, l, !0);
        },
        _scrollToY: function(o) {
            var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0, e = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], i = arguments.length > 3 && void 0 !== arguments[3] && arguments[3];
            if (this.privateScrollWithAnimation = e ? 1 : 0, this.usePageScroll) {
                i && -1 !== this.pageScrollTop && (o += this.pageScrollTop);
                var r = o - t;
                l.index.pageScrollTo({
                    scrollTop: r,
                    duration: e ? 100 : 0
                }), -1 !== this.pageScrollTop && (this.pageScrollTop = r);
            } else i && (o += this.oldScrollTop), this.scrollTop = o - t, this.oldScrollTop = this.scrollTop;
        },
        _scroll: function(o) {
            this.$emit("scroll", o);
            var t = o.detail.scrollTop;
            this.finalUseVirtualList && this._updateVirtualScroll(t, this.oldScrollTop - t), 
            this.oldScrollTop = t;
            var l = o.detail.scrollHeight - this.oldScrollTop;
            !this.isIos && this._checkScrolledToBottom(l);
        },
        _doCheckScrollViewShouldFullHeight: function(o) {
            var t = this;
            this.autoFullHeight && this.usePageScroll && this.isTotalChangeFromAddData ? this.$nextTick(function() {
                t._checkScrollViewShouldFullHeight(function(l, e) {
                    t._preCheckShowNoMoreInside(o, l, e);
                });
            }) : this._preCheckShowNoMoreInside(o);
        },
        _checkScrollViewShouldFullHeight: function(l) {
            var e = this;
            return t(o().mark(function t() {
                var i, r, n, c;
                return o().wrap(function(o) {
                    for (;;) switch (o.prev = o.next) {
                      case 0:
                        return o.prev = 0, o.next = 3, e._getNodeClientRect(".zp-scroll-view");

                      case 3:
                        return i = o.sent, o.next = 6, e._getNodeClientRect(".zp-paging-container-content");

                      case 6:
                        if (r = o.sent, i && r) {
                            o.next = 9;
                            break;
                        }
                        return o.abrupt("return");

                      case 9:
                        n = r[0].height, c = i[0].top, e.isAddedData && n + c <= e.windowHeight ? (e._setAutoHeight(!0, i), 
                        l(i, r)) : (e._setAutoHeight(!1), l(null, null)), o.next = 16;
                        break;

                      case 13:
                        o.prev = 13, o.t0 = o.catch(0), l(null, null);

                      case 16:
                      case "end":
                        return o.stop();
                    }
                }, t, null, [ [ 0, 13 ] ]);
            }))();
        },
        _scrollTopChange: function(o, t) {
            this.$emit("scrollTopChange", o), this.$emit("update:scrollTop", o), this._checkShouldShowBackToTop(o);
            var l = this.isIos ? o > 5 ? 6 : 0 : o > 105 ? 106 : o > 5 ? 6 : 0;
            t && this.wxsPageScrollTop !== l ? this.wxsPageScrollTop = l : t || this.wxsScrollTop === l || (this.wxsScrollTop = l, 
            l > 6 && (this.scrollEnable = !0));
        },
        _updatePageScrollTopOrBottomHeight: function(o) {
            var t = this;
            if (this.usePageScroll) {
                this._doCheckScrollViewShouldFullHeight(this.realTotalData);
                var l = ".zp-page-".concat(o), i = "margin".concat(o.slice(0, 1).toUpperCase() + o.slice(1)), r = this.safeAreaInsetBottom;
                this.$nextTick(function() {
                    e.u.delay(function() {
                        t._getNodeClientRect(l).then(function(l) {
                            if (l) {
                                var e = l[0].height;
                                "bottom" === o ? r && (e += t.safeAreaBottom) : t.cacheTopHeight = e, t.$set(t.scrollViewStyle, i, "".concat(e, "px"));
                            } else r && t.$set(t.scrollViewStyle, i, "".concat(t.safeAreaBottom, "px"));
                        });
                    }, 0);
                });
            }
        }
    }
};

exports.scrollerModule = r;